﻿@model Himall.Web.Areas.SellerAdmin.Models.LimitTimeMarketModel

@{
    ViewBag.Title = "AddLimitItem";
}


<link rel="stylesheet" type="text/css" href="~/Content/bootstrap-datetimepicker.min.css">
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
    $(function () {
        $("#Title").focus();
        $("#Title").val('限时折扣');
        $(".start_datetime").val('@DateTime.Now.ToString("yyyy-MM-dd")');

        $(".start_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd hh:ii:ss',
            autoclose: true,
            weekStart: 1,
            minView: 0
        });
        $(".end_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd hh:ii:ss',
            autoclose: true,
            weekStart: 1,
            minView: 0
        });
        $('.end_datetime').datetimepicker('setEndDate', "@ViewBag.EndTime");
        $('.end_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
        $('.start_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
        $('.start_datetime').datetimepicker('setEndDate', "@ViewBag.EndTime");
        //$(".start_datetime").click(function () {
        //    $('.end_datetime').datetimepicker('show');
        //});
        //$(".end_datetime").click(function () {
        //    $('.start_datetime').datetimepicker('show');
        //});

        $('.start_datetime').on('changeDate', function () {
            if ($(".end_datetime").val()) {
                if ($(".start_datetime").val() > $(".end_datetime").val()) {
                    $('.end_datetime').val($(".start_datetime").val());
                }
            }

            $('.end_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
            //alert($(".start_datetime").val());
        });
        $('.end_datetime').on('changeDate', function () {
            $('.start_datetime').datetimepicker('setEndDate', $(".end_datetime").val());
        });


    });
</script>
<script src="~/Scripts/v.js"></script>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>限时购</strong>
        <li><a href="./Management">活动管理</a></li>
        <li class="active"><a>新增限时购</a></li>
        <li class=""><a href="./BuyService">购买服务</a></li>
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>显示店铺已经申请的限时购活动列表</p>
            </div>
        </em>
    </ul>
    @using (Html.BeginForm("AddLimitItem", "LimitTimeBuy", FormMethod.Post, new { id = "form1" }))
    {
        <div class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>活动标题：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.Title, new { htmlAttributes = new { @class = "form-control input-sm" } }) </div>
                <div class="col-sm-5"><span class="help-default">活动标题是商家对限时折扣活动的别名.</span></div>

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>活动商品：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.ProductName, new { htmlAttributes = new { @class = "form-control input-sm", @readonly = "readonly" } })</div>
                <div class="col-sm-3"><a class="btn btn-primary btn-sm" id="SelectProduct"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp; 选择商品</a></div>
                <input type="hidden" id="ProductId" name="ProductId" value="" />
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>原价格：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.ProductPrice, new { htmlAttributes = new { @class = "form-control input-sm", @readonly = "readonly" } })</div>
                <div class="col-sm-5"><span class="help-default">选择商品之后，会自动填充.</span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>限时购价格：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.Price, new { htmlAttributes = new { @class = "form-control input-sm" } })</div>
                <div class="col-sm-5"><span class="help-default">限时购价格必须低于原价格；在活动期内，不能修改商品价格.</span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>活动分类：</label>
                <div class="col-sm-3">@Html.GenerateSelectHtml((List<SelectListItem>)ViewBag.Cate, "CategoryName")</div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>开始时间：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.StartTime, new { htmlAttributes = new { @class = "form-control input-sm start_datetime" } })</div>
                <div class="col-sm-5"><span class="help-default">开始时间最好晚于当前时间+默认的2天审核时间.</span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>结束时间：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.EndTime, new { htmlAttributes = new { @class = "form-control input-sm end_datetime"} })</div>
                <div class="col-sm-5"><span class="help-default">结束时间必须晚于开始时间.</span></div>
            </div>
            @*@if (Model != null)
                {
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>库存数量：</label>
                        <div class="col-sm-3">@Html.EditorFor(item => item.Stock, new { htmlAttributes = new { @class = "form-control input-sm", @readonly = "readonly" } }) 件</div>
                    </div>
                }
                else
                {
                <div class="form-group">
                    <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>库存数量：</label>
                    <div class="col-sm-3">@Html.EditorFor(item => item.Stock, new { htmlAttributes = new { @class = "form-control input-sm" } }) 件</div>
                </div>
                }*@
            @Html.HiddenFor(item => item.Stock, new { htmlAttributes = new { @class = "form-control input-sm" } })
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>购买限制：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.MaxSaleCount, new { htmlAttributes = new { @class = "form-control input-sm" } })</div>
                <div class="col-sm-5"><span class="help-default">单个人最多购买数量.</span></div>
            </div>
            <div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
                	<button type="submit" class="btn btn-primary">保存</button><label class="label-inline" for=""><a href="./Management">返回</a></label>
				</div>
            </div>
        </div>
    }
</div>
<script src="~/Scripts/jquery.himallLinkage.nocreate.js"></script>
<script src="~/Scripts/jquery.hiMallDatagrid.js"></script>
<script src="~/Scripts/jquery.productSelector.js"></script>
<script>
    $(function () {
        $("#SelectProduct").click(function () {
            $.productSelector.show(null, function (selectedProducts) {
                console.log(selectedProducts);
                $("#ProductId").val(selectedProducts[0].id);
                $("#ProductName").val(selectedProducts[0].name);
                $("#ProductPrice").val(selectedProducts[0].price);
            }, 'selleradmin', false);
        });
    });
    var a = v({
        form: 'form1',
        ajaxSubmit: true,
        beforeSubmit: function () {
            loadingobj = showLoading();
        },
        afterSubmit: function (d) {// 表单提交成功回调
            loadingobj.close();
            if (d.success) {
                $.dialog.succeedTips("保存成功！", function () {
                    window.location.href="@Url.Action("Management")";
                }, 0.5);
            } else {
                $.dialog.errorTips(d.msg, null, 1);
            }
        }
    });
    a.add(
        {
            target: 'Title',
            empty: true,
            ruleType: 'required',// v.js规则验证
            error: '请您填写活动标题'
        },
        {
            target: 'ProductName',
            empty: true,
            ruleType: 'required',// v.js规则验证
            error: '请您选择商品'
        }, {
            target: 'Price',
            empty: true,
            ruleType: 'money',// v.js规则验证
            fnRule: function () {
                var a = $('#ProductPrice').val(),
                      b = $('#Price').val();
                try {
                    a = parseFloat(a);
                } catch (ex) {
                    a = 0;
                }
                try {
                    b = parseFloat(b);
                } catch (ex) {
                    b = 0;
                }
                if (b >= a || b<0 || a<0) {
                    return false;
                }
            },
            error: '只能为数字，  大于0且必须低于原价格'
        }, {
            target: 'StartTime',
            ruleType: 'required',// v.js规则验证
            error: '请选择活动开始时间'
        }, {
            target: 'EndTime',
            ruleType: 'required',// v.js规则验证
            error: '请选择活动结束时间'
        }, {
            target: 'MaxSaleCount',
            empty: true,
            ruleType: 'uint&&(value>0)',// v.js规则验证
            error: '最大购买数只能为数字，  且大于0'
        });



</script>

